package csdn.xiancheng.li07;
//消费者
public class Customer extends Thread{
    private Bum bum;

    public Customer(String name,Bum bum){
        super(name);
        this.bum=bum;
    }

    //吃包子
    @Override
    public void run() {
        //持续消费
        while (true) {
        synchronized(bum){
            //如果没有包子就等待
            if(!bum.flag){
                try {
                    bum.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //有包子就吃
            System.out.println(getName()+"框框炫包子");
            bum.num--;

                // 如果包子吃完了，通知生产者生产
                if (bum.num <= 0) {
                    bum.flag = false;
                    bum.notify();  // 通知生产者
                }
        }
    }
}
}